SET(CMAKE_VERBOSE_MAKEFILE ON)
PROJECT(GTK)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE(UsePkgConfig)
 
FIND_PACKAGE(GTK)
 
IF (GTK_FOUND)
     INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIR})
      ADD_DEFINITIONS(-DHAVE_GTK)
     MESSAGE("GTK 1.x found and used as GUI\n")
ELSE (GTK_FOUND)
     PKGCONFIG(gtk+-2.0 GTK2_INCLUDE_DIR GTK2_LINK_DIR GTK2_LINK_FLAGS GTK2_CFLAGS)
     PKGCONFIG(gthread-2.0 GTHREAD_INCLUDE_DIR GTHREAD_LINK_DIR GTHREAD_LINK_FLAGS+- GTHREAD_CFLAGS)
      IF (GTK2_INCLUDE_DIR)
          SET(CMAKE_C_FLAGS "${GTK2_CFLAGS} ${GTHREAD_CFLAGS}")
          STRING(REGEX REPLACE "-l" "" GTK_LIBRARIES "${GTK2_LINK_FLAGS} ${GTHREAD_LINK_FLAGS}")
          SEPARATE_ARGUMENTS(GTK_LIBRARIES)
          ADD_DEFINITIONS(-DHAVE_GTK2)
          MESSAGE("GTK 2.x found and used as GUI\n")
      ELSE (GTK2_INCLUDE_DIR)
          MESSAGE(FATAL_ERROR "GTK or GTK2 is required to build this project.")
      ENDIF (GTK2_INCLUDE_DIR)
ENDIF (GTK_FOUND)

ADD_EXECUTABLE(main test_gtk1.c)
TARGET_LINK_LIBRARIES(main ${GTK2_LINK_FLAGS})
